import util from './util'
import { checkSensWords } from './domains'
export default {
  install(Vue, opts){
    Vue.mixin({
      data(){
        return {

        }
      },
      computed:{
        curUserInfo(){
          return JSON.parse(localStorage.getItem('md_userInfo') || '{}')
        }
      },
      methods:{
        validSensWords (rule, value, callback){
          checkSensWords({ keyWord: value }).then(res => {
            if(res === 'no') return callback()
            callback(`输入包含敏感词，请检查修改后重新提交`)
          }).catch(err => {
            console.log('validSensWords error', err)
            callback()
          })
          
          // let words = util.hasSensWords(value)
          // if(!words) return callback()
          // callback(`【${words}】输入不符合要求，请检查修改后重新提交`)
        },
        validMobile(rule, value, callback){
          if(util.isMobile(value)) return callback()

          return callback(new Error())
        },
        validIdCode(rule, value, callback){
          if(util.isIdCode(value)) return callback()

          return callback(new Error())
        },
        validEmail(rule, value, callback){
          if(util.isEmail(value)) return callback()

          return callback(new Error())
        }
      }
    })
  }
}